<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>注册</title>
  <link rel="stylesheet" href="../../resource/core/mp/_assets/css/scrollbar.css?_v=20150112">
  <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
  <script src="../../resource/core/wechat/jweixinapi.js"></script>
  <jsp:include page="../../../main/mp/inc.jsp"	/>
  <script src="../../resource/core/mp/jquery.mobile/js/jsAddress3.js?date=2015-6-24"></script>
</head>
<body>


<div data-role="page" >
  <div data-role="header" data-position="fixed" data-theme="a">
    <h1 style="float:left;margin: 0 10px;color: #121010;"><i class="fa fa-user"></i> 注册</h1>
  </div>
  <div class="ui-content jqm-content jqm-fullwidth" role="main">
    <form  id="form-common" method="post" action="register/userRegister" data-ajax="false">
      <input type="hidden" name="openId" id="openId" value="${openId}" />
      <div class="ui-field-contain">
        <label>姓名</label>
        <span><input type="text" name="name" id="name"></span>
      </div>
      <div class="ui-field-contain">
        <label>登录账号</label>
        <span><input type="text" name="username" id="username"></span>
      </div>
      <div class="ui-field-contain">
        <label>登录密码</label>
        <span><input type="password" name="password" id="password"></span>
      </div>
      <div class="ui-field-contain">
        <label>密码确认</label>
        <span><input type="password" name="passwordConfirm" id="passwordConfirm"></span>
      </div>
    </form>
    <div id="btn-save-common" style="margin:0 auto;width:120px;border-radius:3px;background:#2DA7E0;line-height:45px;text-align:center;color:#fff;font-size:20px;cursor:pointer;" >提交</div>
  </div>
</div>
</body>


<script>

  $(function(){

      fn_member_create_validate();
      $("#btn-save-common").click(function(e){

          if (!$('#form-common').valid()) {
              return false;
          }
          $("#btn-save-common").hide();
          $.mobile.loading( "show", {
              text: "正在保存，请稍后...",
              textVisible: true,
              theme: "b",
              textonly: false,
              html: ""
          });
          $.ajax({
              type: "POST",
              url: $("form#form-common").attr("action"),
              cache:false,
              dataType:"json",
              data: $("form#form-common").serialize(),
              success: function(data){
                  hide();
                  if(data.state == 1){
                      alert("注册成功!");
                      var datas={"username":$("#username").val(),"password":$("#password").val(),"openId":$("#openId").val()};
                      __ajax_post("connectMp",datas,function(pdata){
                          location.replace("<%=path%>/mp/index");
                      });
                  }else{
                      alert("注册失败!");
                      location.replace("<%=path%>/mp/login");
                  }
              }
          });
      });
  });

  // 表单数据校验
  function fn_member_create_validate() {
    __init_validate('form-common', {
      rules : {
        username : {
          required : true,
          remote : {
            type: 'post',
            url: '<%=path%>/mp/user/validate/account',
            data: {
              username: function() {return $('#form-common').find('#username').val()}
            }
          }
        },
        name : {
          required : true
        },
        password : {
          required : true
        },
        passwordConfirm : {
          required : true,
          equalTo : '#password'
        }
      },
      messages : {
        username : {
          required : '请输入成员手机号/邮箱账号',
          remote : '请输入有效的手机号/邮箱账号, 或已被使用'
        },
        name : {
          required : '请输入成员姓名'
        },
        password : {
          required : '请输入登录密码'
        },
        passwordConfirm : {
          required : '请输入确认密码',
          equalTo : '请确保两次输入密码一致'
        }
      }
    },1);
  }

</script>